Ext.define('DragonApp.view.basic.Controller', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.basic',

    onSubmitClick: function(button, e, options) {

        var me = this;

        //查询表单
        var queryForm = this.getView();
        var form = queryForm.getForm();

        if (!form.isValid()) return;

        var formValue = form.getValues();

        //数据表单
        var basicForm = Ext.ComponentQuery.query('basicform')[0];

        basicForm.mask('查询中...');

        Ext.data.JsonP.request({

            url: DragonApp.ux.config.Config.getUrl('/index/User/queryBasicInfo/'),
            callbackKey: "callback",
            params: formValue,
            async: false,
            scope: me,
            success: function(result) {

                var form = basicForm.getForm();
                basicForm.unmask();

                switch (result.success) {
                    case true:
                        form.setValues(result.data);
                        var channelField = Ext.ComponentQuery.query('channelcombobox')[0];
                        channelField.on('beforequery', function() {
                            return false
                        });
                        channelField.setReadOnly(true);
                        break;
                    case false:
                        form.reset();
                        DragonApp.util.Msg.showToast(result.msg);
                        break;
                    default:
                        Ext.Msg.alert('提示', result.msg);
                        break;
                }
            },
            failure: function(result) {
                basicForm.unmask();
                Ext.Msg.alert('提示', result);
            }
        });
    },

    onTextFieldSpecialKey: function(field, e, options) {
        if (e.getKey() === e.ENTER) {
            if (this.getView().getForm().isValid()) {
                this.onSubmitClick();
            }
        }
    }
});